#include <iostream>

long long const maxn = 100007;
long long a[maxn];
long long n;

int main()
{
	std::cin >> n;
	for (long long i = 1; i <= n; i++) std::cin >> a[i];

	long long en = 0, cost = 0;
	for (long long i = 1; i <= n; i++) {
		if (a[i] <= a[i - 1]) {
			en += a[i - 1] - a[i];
		} else {
			if (en < a[i] - a[i - 1]) {
				cost += a[i] - a[i - 1] - en;
				en = 0;
			} else
				en -= a[i] - a[i - 1];
		}
	}
	std::cout << cost << '\n';
}

